package com.jelly.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jelly.entity.WechatUser;
import com.jelly.mapper.WechatUserMapper;
import com.jelly.service.WechatUserService;

@Service
public class WechatUserServiceImpl implements WechatUserService {
	
	@Resource
	private WechatUserMapper wechatUserMapper;
	
	@Override
	public WechatUser findByOpenid(String openId) {
		QueryWrapper<WechatUser> query = new QueryWrapper<>();
		query.eq("openid", openId);
		return wechatUserMapper.selectOne(query);
	}
	
	@Transactional
	@Override
	public Long insert(WechatUser user) {
		wechatUserMapper.insert(user);
		return user.getId();
	}

	@Override
	public void update(WechatUser user) {
		wechatUserMapper.updateById(user);
	}

	@Override
	public WechatUser findById(Long id) {
		return wechatUserMapper.selectById(id);
	}

}
